function intersect(nums1: number[], nums2: number[]): number[] {
    const result: number[] = [];
    let p =0;
    let q =0;
    nums1.sort((a, b) =>a-b);
    nums2.sort((a, b) =>a-b);
    while (p < nums1.length && q < nums2.length) {
        if(nums1[p] > nums2[q]){
            q++;
        } else if(nums1[p] < nums2[q]){
            p++;
        } else if(nums1[p] === nums2[q]){
            result.push(nums1[p]);
            p++;q++;
        }
    }
    // console.log(result);
    return result;
};

const nums3 = [4,9,5], nums4 = [9,4,9,8,4]
intersect(nums3,nums4)